<?php
function req($url, $data=false) {
	$c = curl_init();
	curl_setopt_array($c, array(
		CURLOPT_URL => $url,
		CURLOPT_HTTPHEADER => array( 'User-Agent: Mozilla/5.0 (Windows NT 5.1; U; zh-cn; rv:1.8.1) Gecko/20091102 Firefox/3.5.5' ),
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_FOLLOWLOCATION => true,
		CURLOPT_FRESH_CONNECT => true,
		CURLOPT_DNS_USE_GLOBAL_CACHE => true
	));
	if (!strpos($url, 'https')) {
		curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
	}
	if ($data) {
		curl_setopt_array($c, array(
			CURLOPT_POST => 1,
			CURLOPT_POSTFIELDS => $data
		));
	}
	$r = curl_exec($c);
	curl_close($c);
	return $r;
}
/* function between($str, $strStart, $strEnd) {
    $posStart = strpos($str, $strStart);
    $posEnd = strpos($str, $strEnd, $posStart);
    return substr($str, $posStart + strlen($strStart), $posEnd - $posStart - strlen($strStart));
} */
function get_reg_content() {
	$twitter = req('https://twitter.com/signup', false, false);
    $recaptha_params = between($twitter, 'https://api-secure.recaptcha.net/challenge', '">');
    $recaptcha = req('https://api-secure.recaptcha.net/challenge'.$recaptha_params, false, false);
    $auth_key = between($twitter, '<input name="authenticity_token" type="hidden" value="', '" />');
    $challenge = between($recaptcha, "challenge : '", "',");
	$content = 
'<form action="'.$_SERVER["REQUEST_URI"].'" method="POST">
	<input name="authenticity_token" type="hidden" value="'.$auth_key.'" />
	<input id="follow" name="follow" type="hidden" />
	<input name="recaptcha_challenge_field" type="hidden" value="'.$challenge.'" />
	<p>
		<label for="user_name">昵称（可以为中文）</label><br/>
		<input autocomplete="off" class="text_field" id="user_name" name="user[name]" type="text" /><span></span>
	<p>
	<p>
		<label for="user_screen_name">用户名（用于登录，只能是英文字母、数字及下划线的组合）</label><br/>
		<input autocomplete="off" class="text_field" id="user_screen_name" maxlength="15" name="user[screen_name]" type="text" /><span></span>
	</p>
	<p>
		<label for="user_user_password">密码（至少六位）</label><br/>
		<input autocomplete="off" class="text_field" id="user_user_password" name="user[user_password]" type="password" /><span></span>
	</p>
	<p>
		<label for="user_email">邮箱（请填写真实邮箱，注册成功后会收到注册邮件）</label><br/>
		<input autocomplete="off" class="text_field" id="user_email" name="user[email]" type="text" /><span></span>
	</p>
	<input name="user[send_email_newsletter]" type="hidden" value="1" />
	<p>
		<label for="recaptcha_response_field">输入下面的两个单词（以半角空格分开）</label><br/>
		<img src="'.BASE_URF.'common/reg_image.php?c='.$challenge.'" alt="recaptcha" /><br/>                
	<input type="text" id="recaptcha_response_field" name="recaptcha_response_field" class="text_field">
	</p>
	<input name="user[send_email_newsletter]" type="hidden" value="0" />
	<p><input alt="我同意，创建我的帐号" class="btn btn-m" id="user_create_submit" name="commit" onclick="this.disabled=true,this.form.submit();" type="submit" value="立即注册" /></p>
</form>';
	return $content;
}
?>